package com.lg.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.lg.redis.simple.RedisClient;
import com.lg.shiro.RedisContext;

@Aspect
@Order(2)
@Component
public class JedisAspect {
	@Autowired
	private RedisClient redisClient;
     @Pointcut("@annotation(com.lg.annotation.JedisClient)")
	public void pointcut() {
	}
	
     @Around(value="pointcut()")
     public void around(ProceedingJoinPoint proceedingJoinPoint) {
    	 redisClient.getJedis();
    	 System.out.println("1");
    	 try {
			Object[] args = proceedingJoinPoint.getArgs();
			 Signature signature = proceedingJoinPoint.getSignature();
			 Object proceed = proceedingJoinPoint.proceed();
			 System.out.println(2);
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			System.out.println(3);
			RedisContext.get().close();
			RedisContext.jedisContext.set(null);
		}
     }
}
